/**
 * 存储localStorage
 */
export const setStore = (name:string,value:string[]|string) => {
    if (!name) return;
    window.localStorage.setItem(name,JSON.stringify(value));
}

/**
 * 获取localStorage
 */
export const getStore = (name:string) => {
    if (!name) return;
    return window.localStorage.getItem(name);
}

/**
 * 获取当前滚动条的位置
 */
export const getScrollTop = () => {
    let scrollTop=0
    if(document.documentElement&&document.documentElement.scrollTop){
        scrollTop = document.documentElement.scrollTop
    }else if(document.body){
        scrollTop = document.body.scrollTop
    }
    return scrollTop
}

/**
 * 获取当前可视范围的高度
 */
export const getClientHeight = () => {
    let clientHeight = 0
    if(document.body.clientHeight&&document.documentElement.clientHeight){
        clientHeight = Math.min(document.body.clientHeight,document.documentElement.clientHeight)
    }else{
        clientHeight = Math.max(document.body.clientHeight,document.documentElement.clientHeight)
    }
    return clientHeight
}

/**
 * 获取文档完整的高度
 */
export const getScrollHeight = () => {
    return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
}

/**
 * 无搜索结果警告
 */
export const messageNoAnswer = function(){
    // @ts-ignore
    this.$message({
        message: '很抱歉！无搜索结果，请重新输入',
        type: 'warning'
    });
}

/**
 * 根据传入的图片地址进行解析
 */
export const getImgPath = function(path:string) {
    let suffix;
    if (!path) {
        return '//elm.cangdu.org/img/default.jpg'
    }
    if (path.indexOf('jpeg') !== -1) {
        suffix = '.jpeg'
    } else {
        suffix = '.png'
    }
    let url = '/' + path.substr(0, 1) + '/' + path.substr(1, 2) + '/' + path.substr(3) + suffix;
    return 'https://fuss10.elemecdn.com' + url
}
